
package websocket.handler;

import org.springframework.stereotype.Component;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.socket.WebSocketSession;
import reactor.core.publisher.Mono;

/**
 * @author guo
 */
@Component
public class EchoHandler implements WebSocketHandler {
    @Override
    public Mono<Void> handle(final WebSocketSession session) {

        return session.send(session.receive().map(msg ->
                                                        session.textMessage(
                                                                "服务端返回：小明， " + msg.getPayloadAsText()
                                                        )
                                                 )
        );
    }
}
